package com.ming.DaoImp;

import com.ming.Dao.product_relationDao;
import com.ming.entity.product_relation;
import com.ming.util.Database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.ming.Dao.*;

/**
 * Created by Administrator on 2018/8/6 0006.
 */
public class product_relationDaoImp extends Database implements product_relationDao {
    public List<product_relation> findProductRelationDaos(int id){
    List<product_relation> list = new ArrayList<product_relation>();
        Connection con = null;
        PreparedStatement stat =null;
        ResultSet rs = null;
        filterDao f = new filterDaoImp();
        String sql = "select * from product_relation where waterid = ? ";
        try {
            con = Database.getConnection();
            stat = con.prepareStatement(sql);
            stat.setInt(1,id);
            rs = stat.executeQuery();
            while(rs.next()){
                product_relation pr = new product_relation();
                pr.setWprid(rs.getInt("wprid"));
                pr.setFilterid(rs.getInt("filterid"));
                pr.setReplacementTime(rs.getString("replacementTime"));
                pr.setWaterid(rs.getInt("waterid"));
                pr.setFlist(f.findCaoDan(pr.getFilterid()));
                list.add(pr);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            Database.closeConnection(con,stat,rs);
        }
        return list;
    }
}
